package com.pureut.equipment.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.equipment.domain.InspectionItem;
import com.pureut.equipment.domain.dto.InspectionItemDto;
import com.pureut.equipment.domain.dto.MaintenanceWorkOrderDto;
import com.pureut.equipment.domain.vo.InspectionItemVo;
import com.pureut.equipment.domain.vo.MaintenanceWorkOrderVo;
import com.pureut.equipment.service.InspectionItemService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 *
 * Author: 点验项目控制层
 * Date:2023/04/24 15:20
 * @DESC
 */
@RestController
@RequestMapping("/inspection-item")
public class InspectionItemController extends BaseController {

    /**
     * 点验项目service
     */
    @Resource
    InspectionItemService inspectionItemService;

    /**
     * 点验项目列表
     * @param inspectionItemVo
     * @return
     */
    @RequiresPermissions("device:spotCheck:project:list")
    @GetMapping("/list")
    public TableDataInfo list(InspectionItemVo inspectionItemVo) {
        startPage();
        List<InspectionItemDto> list = inspectionItemService.getList(inspectionItemVo);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @RequiresPermissions("device:spotCheck:workorder:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody InspectionItemVo inspectionItemVo) throws Exception {
        return toAjax(inspectionItemService.add(inspectionItemVo));
    }

    /**
     * 删除
     */
    @RequiresPermissions("device:spotCheck:workorder:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteInspectionItem/{id}")
    public AjaxResult deleteInspectionItem(@PathVariable("id") Long id) {
        return toAjax(inspectionItemService.deleteInspectionItem(id));
    }

    /**
     * 修改
     */
    @RequiresPermissions("device:spotCheck:workorder:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping("/updateInspectionItem")
    public AjaxResult updateInspectionItem(@RequestBody InspectionItemVo inspectionItemVo) {
        return toAjax(inspectionItemService.updateInspectionItem(inspectionItemVo));
    }

    /**
     * 查看
     */
    @RequiresPermissions("device:spotCheck:workorder:query")
    @GetMapping("/queryInspectionItem/{id}")
    public AjaxResult queryInspectionItem(@PathVariable("id") Long id) {
        return AjaxResult.success(inspectionItemService.queryInspectionItem(id));
    }
}
